| Total Complexity | 3 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 19 | |||
| 20 | @Controller('app/customers/add') |
||
| 21 | @UseGuards(IsAuthenticatedGuard) |
||
| 22 | export class AddCustomerController { |
||
| 23 | constructor( |
||
| 24 | @Inject('ICommandBus') |
||
| 25 | private readonly commandBus: ICommandBus, |
||
| 26 | private readonly resolver: RouteNameResolver |
||
| 27 | ) {} |
||
| 28 | |||
| 29 | @Get() |
||
| 30 | @WithName('crm_customers_add') |
||
| 31 | @Render('pages/customers/add.njk') |
||
| 32 | public async get() { |
||
| 33 | return {}; |
||
| 34 | } |
||
| 35 | |||
| 36 | @Post() |
||
| 37 | public async post(@Body() customerDto: CustomerDTO, @Res() res: Response) { |
||
| 38 | const { street, city, zipCode, country, name } = customerDto; |
||
| 39 | |||
| 40 | try { |
||
| 41 | await this.commandBus.execute( |
||
| 42 | new CreateCustomerCommand(name, street, city, zipCode, country) |
||
| 43 | ); |
||
| 44 | |||
| 45 | res.redirect(303, this.resolver.resolve('crm_customers_list')); |
||
| 46 | } catch (e) { |
||
| 47 | throw new BadRequestException(e.message); |
||
| 48 | } |
||
| 51 |